//
//  shareView.m
//  meituan
//
//  Created by apple on 16/6/17.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "shareView.h"
#import "sharButten.h"
@interface shareView()
@property(nonatomic,strong)UIView *view;
@property(nonatomic,strong)UILabel *lable;
@property(nonatomic,strong)NSMutableArray *array;
@property(nonatomic,strong)NSMutableArray *buttenarray;
@end
@implementation shareView
-(NSMutableArray *)buttenarray
{
    if (!_buttenarray) {
        _buttenarray = [NSMutableArray arrayWithObjects:@[@"weixinshar.png",@"微信"],@[@"pengyouquan.png",@"朋友圈"],@[@"QQ.png",@"QQ"],@[@"QQkongjian.png",@"QQ空间"],@[@"weiboshar.png",@"微博"], nil];
    }
    return _buttenarray;
}
-(NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;

}
-(void)setUpUI
{
    self.backgroundColor =kcolor(0, 0, 0, 0.5);
    self.hidden = YES;
    
    self.view = [[UIView alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.view];
    self.lable = [[UILabel alloc]init];
    self.lable.text = @"分享到:";
    [self.view addSubview:self.lable];
    
    for (NSInteger i=0; i<5; i++) {
        sharButten *butten = [[sharButten alloc]init];
        butten.sharImageView.image = [UIImage imageNamed:self.buttenarray[i][0]];
        butten.sharLable.text = self.buttenarray[i][1];
        butten.tag = i;
        [butten addTarget:self action:@selector(sharemessage:) forControlEvents:UIControlEventTouchUpInside];
        [self.array addObject:butten];
        [self.view addSubview:butten];
    }

}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.view.frame = CGRectMake(17.5*Kscr, 200*Kscr, 340*Kscr, 170*Kscr);
    self.lable.frame = CGRectMake(10*Kscr, 25*Kscr, 100*Kscr, 20*Kscr);
    for (NSInteger i=0; i<5; i++) {
       sharButten *butten =  self.array[i];
        butten.frame = CGRectMake(68*Kscr*i, 75*Kscr, 68*Kscr,60*Kscr );
    }

}
-(void)showShareView
{
    self.hidden = NO;
}
-(void)hidenShareView
{
    self.hidden = YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.hidden = YES;
    
}
-(void)sharemessage:(sharButten *)butten
{
//    self.hidden =YES;
//    
//    if (butten.tag==0) {
//        [UMSocialData defaultData].extConfig.title = @"分享的title";
//        [UMSocialData defaultData].extConfig.wechatSessionData.url = @"http://baidu.com";
//        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:
//                                            @"http://www.baidu.com/img/bdlogo.gif"];
//        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:@"分享内嵌文字" image:nil location:nil urlResource:urlResource presentedController:nil completion:^(UMSocialResponseEntity *shareResponse){
//            if (shareResponse.responseCode == UMSResponseCodeSuccess) {
//                NSLog(@"分享成功！");
//            }
//        }];
//    }else if (butten.tag==1)
//    {
//        [UMSocialData defaultData].extConfig.title = @"分享的title";
//        [UMSocialData defaultData].extConfig.wechatTimelineData.url = @"http://baidu.com";
//        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:
//                                            @"http://www.baidu.com/img/bdlogo.gif"];
//        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:@"分享内嵌文字" image:nil location:nil urlResource:urlResource presentedController:nil completion:^(UMSocialResponseEntity *shareResponse){
//            if (shareResponse.responseCode == UMSResponseCodeSuccess) {
//                NSLog(@"分享成功！");
//            }
//        }];
//
//    
//    }else if (butten.tag==2)
//    {
//        [UMSocialData defaultData].extConfig.title = @"分享的title";
//        [UMSocialData defaultData].extConfig.qqData.url = @"http://baidu.com";
//        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:
//                                            @"http://www.baidu.com/img/bdlogo.gif"];
//        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:@"分享内嵌文字" image:nil location:nil urlResource:urlResource presentedController:nil completion:^(UMSocialResponseEntity *shareResponse){
//            if (shareResponse.responseCode == UMSResponseCodeSuccess) {
//                NSLog(@"分享成功！");
//            }
//        }];
//
//    
//    }else if (butten.tag==3)
//    {
//        [UMSocialData defaultData].extConfig.title = @"分享的title";
//        [UMSocialData defaultData].extConfig.qzoneData.url = @"http://baidu.com";
//        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:
//                                            @"http://www.baidu.com/img/bdlogo.gif"];
//        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQzone] content:@"分享内嵌文字" image:nil location:nil urlResource:urlResource presentedController:nil completion:^(UMSocialResponseEntity *shareResponse){
//            if (shareResponse.responseCode == UMSResponseCodeSuccess) {
//                NSLog(@"分享成功！");
//            }
//        }];
//
//    }

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
